<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/header.css" />
	</head>

	<body>

		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<a id="link_submit_password" class="mui-icon mui-icon-right-nav mui-pull-right"
				style="color: white;font-size: 14px;line-height: 27px;">提交</a>
			<h1 class="mui-title title-color">修改密码</h1>
		</header>

		<div class="mui-content">
			<div class="mui-card">
				<div class="mui-input-row">
					<label>原始密码</label>
					<input id="password_old" type="text" class="mui-input-clear" placeholder="请输入原始密码">
				</div>
				<div class="mui-input-row">
					<label>新密码</label>
					<input id="password_new" type="text" class="mui-input-clear" placeholder="请输入新密码">
				</div>
			</div>


		</div>

		<script src="../../js/mui.min.js"></script>
		<script src="../../js/app.js"></script>
		<script type="text/javascript">
			mui.init()

			mui.plusReady(function() {
				var userinfo = app.getGlobalUserInfo();
				
				var password_old = document.getElementById("password_old");
				
				var password_new = document.getElementById("password_new");
				
				var link_submit_password = document.getElementById("link_submit_password");
				link_submit_password.addEventListener("tap",function(){
					if (password_old.value != null && password_new.value != null) {
						if (password_old.value == userinfo.password) {
							mui.ajax(app.serverUrl + "/user/teacher/teacher_update_password?user_id=" + userinfo.user_id + "&password=" + password_new.value, {
									data: {},
									dataType: 'json', //服务器返回json格式数据
									type: 'post', //HTTP请求类型
									timeout: 10000, //超时时间设置为10秒；
									headers: {
										'Content-Type': 'application/json'
									},
									success: function(data) {
										// app.deleteOnlineApplyList();
										// getApplyList();
										app.showToast("密码修改成功，请重新登录！", "success");
										app.userLogout();
										// 打开登录页面
										mui.openWindow({
											url: "login.html",
											id: "login.html",
											extras: {}
										});
									}
								});
						} else {
							app.showToast("原始密码不正确！请重新输入！", "error");
						}
					} else {
						app.showToast("新旧密码均不能为空！请重新输入！", "error");
					}
				})
				
			});
		</script>
	</body>

</html>
